namespace lucere.io.concurrency
{
	public interface ILock
	{
		/// <summary>
		/// Attempts to obtain exclusive access and immediately return
		/// upon success or failure.
		/// </summary>
		/// <returns>true iff exclusive access is obtained</returns>
		bool Obtain();
		/// <summary>
		/// Attempts to obtain an exclusive lock within amount of
		/// time given. Polls once per <see cref="LOCK_POLL_INTERVAL"/>
		/// (currently 1000) milliseconds until lockWaitTimeout is
		/// passed.
		/// </summary>
		/// <param name="lockWaitTimeout">lockWaitTimeout length of time to wait in
		/// milliseconds or <see cref="LOCK_OBTAIN_WAIT_FOREVER"/>to retry forever
		/// </param>
		/// <returns>true if lock was obtained</returns>
		bool Obtain(int lockWaitTimeout);
		/// <summary>
		/// Releases exclusive access.
		/// </summary>
		void Release();

		/// <summary>
		/// Returns true if the resource is currently locked.  Note that one must
		/// still call <see cref="Obtain()"/> before using the resource.
		/// </summary>
		/// <returns></returns>
		bool IsLocked();
	}
}